package com.yuwei.module_patrol.vm

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.vm.BaseViewModel2
import com.yuwei.http.entity.PatrolEntity
import com.yuwei.http.entity.PatrolPointsEntity
import com.yuwei.module_patrol.model.PatrolRepository
import kotlinx.coroutines.launch

class PatrolViewModel : BaseViewModel2<PatrolRepository>() {
    override fun createRepository(): PatrolRepository = PatrolRepository()
    val getPatrolSuccess by lazy {
        MutableLiveData<PatrolEntity>()
    }
    val getPointSuccess by lazy {
        MutableLiveData<PatrolPointsEntity>()
    }
    fun getPatrols(){
       mViewModelScope.launch (mDispatcher){
           val result = mRepository.getPatrolList()
           if(result.code == 200){
                getPatrolSuccess.postValue(result.data)
           }else{
               mErrorLiveData.postValue(result.message)
           }

       }
    }
    fun getPatrolPoints(){
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.getPatrolPoints()
            if(result.code == 200){
                getPointSuccess.postValue(result.data)
            }else{
                mErrorLiveData.postValue(result.message)
            }

        }
    }
}